package com.stony.orc;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>orcTest
 * <p>com.stony.orc
 *
 * @author stony
 * @version 上午11:38
 * @since 2017/12/1
 */
public class TonicDetailWords {

    Map<String, String> keyWords = new HashMap<>();
    public void process(String word) {
        TonicDetailWordsProcess process = support(word);
        if (null != process) {
            String value = process.getWork(word);
            if (ImageUtils.isNotEmpty(value)) {
                keyWords.put(process.getKey(), value);
            }
        }
    }
    public TonicDetailWordsProcess support(String word) {
        for (TonicDetailWordsProcess process : TonicDetailWordsProcess.values()) {
            if (process.support(word)) {
                return process;
            }
        }
        return null;
    }

    public Map<String, String> getKeyWords() {
        return keyWords;
    }

    public enum TonicDetailWordsProcess {
        CLASSIFY("classify", "【类别】"){
            @Override
            protected String getWork(String word) {
                return word.replace(msg,"");
            }
            @Override
            public boolean support(String word) {
                return word.contains(msg);
            }
        },
        TASTE("taste","【性味】") {
            @Override
            protected String getWork(String word) {
                return word.replace(msg,"");
            }
            @Override
            public boolean support(String word) {
                return word.contains(msg);
            }
        },
        MERIDIAN("meridian","【归经】") {
            @Override
            protected String getWork(String word) {
                return word.replace(msg,"");
            }
            @Override
            public boolean support(String word) {
                return word.contains(msg);
            }
        },
        FEATURES("features","【功用主治】") {
            @Override
            protected String getWork(String word) {
                return word.replace(msg,"");
            }
            @Override
            public boolean support(String word) {
                return word.contains(msg);
            }
        },
        AVOID("avoid","【宜忌】") {
            @Override
            protected String getWork(String word) {
                return word.replace(msg,"");
            }
            @Override
            public boolean support(String word) {
                return word.contains(msg);
            }
        },
        INGREDIENT("ingredient","【化学成分】") {
            @Override
            protected String getWork(String word) {
                return word.replace(msg,"");
            }
            @Override
            public boolean support(String word) {
                return word.contains(msg);
            }
        },
        SOURCE("source","【来源】") {
            @Override
            protected String getWork(String word) {
                return word.replace(msg,"");
            }
            @Override
            public boolean support(String word) {
                return word.contains(msg);
            }
        }
        ;
        protected abstract String getWork(String word);

        public abstract boolean support(String word);

        String key;
        String msg;

        TonicDetailWordsProcess(String key, String msg) {
            this.key = key;
            this.msg = msg;
        }

        public String getKey() {
            return key;
        }
    }
}
